//  https://www.luogu.com.cn/problem/P1004

#include<iostream>
using namespace std;

const int N = 15;
typedef long long LL;
LL dp[N * 2][N][N];
LL a[N][N];

int main()
{
    int n, x, y, z;
    cin >> n;
    while (cin >> x >> y >> z && x)
    {
        a[x][y] = z;
    }

    for (int s = 2;s <= 2 * n;s++)
        for (int i1 = 1;i1 <= n;i1++)
            for (int i2 = 1;i2 <= n;i2++)
            {
                int j1 = s - i1, j2 = s - i2;
                if (i1 <= 0 || j1 > n || i2 <= 0 || j2 > n) continue;
                LL t = dp[s - 1][i1][i2];
                t = max(t, dp[s - 1][i1 - 1][i2]);
                t = max(t, dp[s - 1][i1][i2 - 1]);
                t = max(t, dp[s - 1][i1 - 1][i2 - 1]);

                if (i1 == i2)
                    dp[s][i1][i2] = t + a[i1][j1];
                else
                    dp[s][i1][i2] = t + a[i1][j1] + a[i2][j2];
            }
    cout << dp[n * 2][n][n] << endl;
    return 0;
}